package com.zzb.projectfactory.framework.event.service;

import com.alibaba.fastjson.JSON;
import com.zzb.projectfactory.framework.event.dao.SysEventNotifyDAO;
import com.zzb.projectfactory.framework.event.dao.jpa.SysEventNotifyRepository;
import com.zzb.projectfactory.framework.event.entity.SysEventNotify;
import com.zzb.projectfactory.framework.role.entity.User;
import com.zzb.projectfactory.framework.common.BaseResponse;
import com.zzb.projectfactory.framework.common.BaseService;
import com.zzb.projectfactory.framework.common.ServiceException;
import com.zzb.projectfactory.framework.validator.annotation.ValidatorEnabled;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* 事件通知方法 service类
*/
@Service("sysEventNotifyService")
public class SysEventNotifyService extends BaseService<SysEventNotifyDAO,SysEventNotify,SysEventNotifyRepository> {
    private static final Logger logger = LoggerFactory.getLogger(SysEventNotifyService.class);
    @Autowired
    private SysEventNotifyDAO sysEventNotifyDAO;
    @Override
    public SysEventNotifyDAO getDAO() {
        return sysEventNotifyDAO;
    }
    /**删除事件通知方法*/
    public BaseResponse deleteSysEventNotify(String id,User operate) throws ServiceException {
        //TODO 删除应该不仅仅这么简单的操作，后面想到了再加 ZZB 20170222
        return delete(id);
    }
    /**保存事件通知方法*/
    @ValidatorEnabled
    public BaseResponse<SysEventNotify> saveSysEventNotify(SysEventNotify sysEventNotify, User operator) throws ServiceException{
        logger.info("正在保存事件通知方法["+ JSON.toJSONString(sysEventNotify)+"]["+JSON.toJSONString(operator)+"]");
        //TODO 保存应该不仅仅这么简单的操作，后面想到了再加 ZZB 20170222
        return createOrUpdate(sysEventNotify,operator);
    }

    /**通过eventId获取事件通知列表*/
    public List<SysEventNotify> findByEventIdOrderByExecuteOrderAsc(String eventId){
        return getDAO().getRepository().findByEventIdAndActivateOrderByExecuteOrderAsc(eventId,true);
    }
}
